#include "stdafx.h"
#include "dbgproxy_h.h"
#include <dbgeng.h>

class CDbgService : public IDbgService
{
public:
	ULONG m_RefCount;

	CRITICAL_SECTION m_CommandCS;
	PStrList m_ListFirst;
	PStrList m_ListLast;
	HANDLE m_hEvent;
	HANDLE m_hThread;

	ULONG m_ProcessId;

	CDbgService();
	~CDbgService();

	PStrList
	Command_Get (
		);

	void
	Command_Push (
		ULONG Flags,
		ULONG OutputControl,
		BSTR bString
		);

	void
	EventLoop (
		);

    BSTR
    CreateBstr (
        __in PSTR pstrString
    );

    // IUnknown
	STDMETHOD( QueryInterface ) (
		REFIID riid,
		void **ppvObject
		);

	STDMETHOD_( ULONG, AddRef ) (
		);

	STDMETHOD_( ULONG, Release ) (
		);

	STDMETHOD (GetTypeInfoCount )(
		UINT *pctinfo);

	STDMETHOD ( GetTypeInfo ) (
		UINT iTInfo,
		LCID lcid,
		ITypeInfo **ppTInfo);

	STDMETHOD (GetIDsOfNames ) (
		REFIID riid,
		LPOLESTR *rgszNames,
		UINT cNames,
		LCID lcid,
		DISPID *rgDispId
		);

	STDMETHOD( Invoke ) (
		DISPID dispIdMember,
		REFIID riid,
		LCID lcid,
		WORD wFlags,
		DISPPARAMS *pDispParams,
		VARIANT *pVarResult,
		EXCEPINFO *pExcepInfo,
		UINT *puArgErr
		);

	STDMETHOD( KernelConnect ) (
		__in BSTR pVal
		);
	
	STDMETHOD( AttachProcess ) (
		__in ULONG ProcessId
		);

    STDMETHOD( IsPointer64Bit) (
        );

	STDMETHOD( GetOutput ) (
		__out BSTR* ppVal
		);

	STDMETHOD( Break ) (
		);

	STDMETHOD( Execute ) (
		__in BSTR pCommand
		);

	STDMETHOD( GetExecutionStatus ) (
		__out PULONG pStatus
		);

	STDMETHOD( GetStackFrameCount ) (
		__out ULONG* pFrameCount
		);

	STDMETHOD( GetStackFrame ) (
		__in ULONG Frame,
		__out DBG_STACK_FRAME* pFrame
		);

    STDMETHOD( GetNearNameByOffset) (
	    __in ULONG64 Offset,
        __in LONG Delta,
        __out BSTR* pSymbol,
        __out ULONG64* pDisplacement
        );

    STDMETHOD( SetSymbolPath ) (
        __in BSTR pSymbolPath
    );

    STDMETHOD( GetCurrentProcessId) (
        __out PULONG64 pId
        );

    STDMETHOD( GetCurrentThreadId) (
        __out PULONG64 pId
        );
};
